package productions;

import exceptions.ParserException;
import lexico.ErrorTable;
import lexico.SymbolTable;
import lexico.TokenClass;

/**
 * @author heekinho
 */
public class BlocoProduction extends AbstractProductionRule {
    /* Muitos dos métodos irão precisar de algo assim: */

    private static BlocoProduction instance = new BlocoProduction();

    public static BlocoProduction getInstance() {
        return instance;
    }

    

    /**
     * Regra: '{' instrucao* '}';
     * @return
     * @throws ParserException
     */
    @Override
    public boolean analyze(SymbolTable st, ErrorTable et) throws ParserException {
        if (!basicParse(st, TokenClass.DELIMITER_OPENING_CURLY_BRACKET)) {
            return false;
        }
        while (InstrucaoProduction.getInstance().analyze(st, et)) {
        }
        if (!basicParse(st, TokenClass.DELIMITER_CLOSING_CURLY_BRACKET)) {
            return skipUntilSynchronize(st, et, "Era esperado um '{'");
        }

        return true;
    }

    @Override
    protected void populateFirst() {
        first.add(TokenClass.DELIMITER_OPENING_CURLY_BRACKET);
    }

    @Override
    protected void populateFollow() {
        //from instrution follow
        follow.add(TokenClass.DELIMITER_CLOSING_CURLY_BRACKET);

        //from se follow
        follow.add(TokenClass.DELIMITER_CLOSING_CURLY_BRACKET);

        //from principal follow
        follow.add(TokenClass.KEYWORD_FUNCAO);
        follow.add(TokenClass.KEYWORD_VARIAVEIS);

        //from funcao follow
        follow.add(TokenClass.KEYWORD_VARIAVEIS);
        follow.add(TokenClass.KEYWORD_FUNCAO);
        
        follow.add(TokenClass.KEYWORD_SENAO);
    }

}
